<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>用户登录</span>
      </div>
      <el-form label-width="120px" @click.native.prevent="login">
        <el-form-item label="用户名:">
          <el-input v-model="form.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码:">
          <el-input v-model="form.password" show-password autocomplete="on"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button native-type="submit" type="primary" size="large">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {},
    };
  },
  methods: {
    async login() {
      const res = await this.$http.post("/login", this.form);
      localStorage.token = res.data.token;
      this.$router.push("/");
      this.$message.success("登录成功!");
    },
  },
};
</script>

<style  scoped>
.box-card {
  width: 40%;
  height: 40%;
  margin: 6rem auto;
}
</style>